package com.xbell.app.cfg;


import org.springframework.beans.BeansException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.client.RestTemplate;


//import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
//import org.springframework.cloud.client.loadbalancer.LoadBalanced;

/**
 * @author 王文胜
 * @date 2020年11月7日-下午11:02:18
 */
@EnableDiscoveryClient
@SpringBootApplication
@ComponentScan(basePackages= {"com.xbell.app"})
@EnableTransactionManagement
@EntityScan(value="com.xbell.app")
@EnableScheduling
public class XbellApplication extends SpringBootServletInitializer implements ApplicationContextAware{


	protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
		return builder.sources(XbellApplication.class);
	}
	public static void main(String[] args) {
		SpringApplication.run(XbellApplication.class, args);
	}
	
	@LoadBalanced
    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

	@Override
    public void setApplicationContext(ApplicationContext ctx) throws BeansException {
//        JedisPoolConfig cfg = new JedisPoolConfig();
//        cfg.setMaxIdle(maxIdel);
//        cfg.setMaxTotal(maxTotal);
//        RedisUtil.initPool(cfg,redis_password,redis_host,redis_port,dbIndex);
    }

	/*
	@Bean
    public Validator validator() {
        ValidatorFactory factory = Validation.byProvider(HibernateValidator.class)
                .configure()
                // 将fail_fast设置为true即可，如果想验证全部，则设置为false或者取消配置即可
                .addProperty("hibernate.validator.fail_fast", "true")
                .buildValidatorFactory();
        return factory.getValidator();
    }
    */

//	@Bean(name="sysQueue")
//	public LinkedBlockingQueue<SysQueue> logQueue()
//	{
//		LinkedBlockingQueue<SysQueue> queue = new LinkedBlockingQueue<SysQueue>(8000);
//		return queue;
//	}

//    @LoadBalanced
//    @Bean
//    public RestTemplate restTemplate() {
//        return new RestTemplate();
//    }


}
